package cc.lj.internal.coupons.interfaces.facade;

import cc.lj.internal.coupons.application.service.MultipleModelAppService;
import cc.lj.internal.coupons.domain.martcap.model.vo.MultipleModelDO;
import cc.lj.internal.coupons.domain.martcap.service.IMultipleModelDomainService;
import cc.lj.internal.coupons.interfaces.dto.MultipleModelDTO;
import cc.lj.internal.coupons.interfaces.dto.MultipleModelListDTO;
import cc.lj.internal.coupons.interfaces.dto.command.MultipleModelAddCommand;
import cc.lj.internal.coupons.interfaces.dto.command.MultipleModelUpdateCommand;
import cc.lj.internal.coupons.interfaces.dto.convert.MultipleModelDTOConvertDO;
import cc.lj.internal.coupons.interfaces.dto.query.MultipleModelListQuery;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.DecimalMin;
import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.stream.Collector;
import java.util.stream.Collectors;

@RestController
@Slf4j
@Api(tags = "倍数模型表接口")
@RequestMapping("/multipleModle")
public class MultipleModelController {

    @Autowired
    private IMultipleModelDomainService multipleModelDomainService;

    @Autowired
    private MultipleModelAppService multipleModelAppService;


    @ApiOperation(value = "倍数模型表添加接口INSERT",notes = "")
    @PostMapping("/add")
    public Integer add(@Valid @RequestBody MultipleModelAddCommand multipleModelAddCommand)
    {
        Integer id = multipleModelDomainService.insert(MultipleModelDTOConvertDO.INSTANCE.convert(multipleModelAddCommand));
        return id;
    }

    @ApiOperation(value = "主键查询倍数模型接口",notes = "")
    @GetMapping("/getById")
    public MultipleModelDTO getById(@DecimalMin("1") @RequestParam Integer id)
    {
       MultipleModelDO multipleModelDO = multipleModelDomainService.getById(id);
       return MultipleModelDTOConvertDO.INSTANCE.convert(multipleModelDO);
    }

    @ApiOperation(value = "修改倍数模型表接口",notes = "1005001014,1005001016")
    @PostMapping("/updateById")
    public Integer updateById(@Valid @RequestBody MultipleModelUpdateCommand multipleModelUpdateCommand)
    {
        return multipleModelDomainService.updateById(MultipleModelDTOConvertDO.INSTANCE.convert(multipleModelUpdateCommand));
    }

    @ApiOperation(value = "倍数模型列表接口",notes = "")
    @PostMapping("/getPage")
    public List<MultipleModelListDTO> getPage(@Valid @RequestBody MultipleModelListQuery multipleModelListQuery)
    {
        List<MultipleModelListDTO> list = multipleModelAppService.getList(multipleModelListQuery);
        return list;
    }

    @ApiOperation(value = "倍数模型列表接口（给下拉菜单使用）")
    @GetMapping("/getByCapId")
    public List<MultipleModelDTO> getByCapId(@DecimalMin("1") @NotNull @RequestParam Integer capId)
    {
        MultipleModelDO multipleModelDO = new MultipleModelDO();
        multipleModelDO.setCapId(capId);

        List<MultipleModelDO> list = multipleModelDomainService.getList(multipleModelDO);
        return list.stream().map(t -> MultipleModelDTOConvertDO.INSTANCE.convert(t)).collect(Collectors.toList());
    }

}
